// utils/pageMixin.js

/**
 * 页面混入 - 自动管理页面路径和底部间距
 */
export const PageMixin = {
  data: {
    pageBottomStyle: ''
  },

  onLoad() {
    this.setPagePath();
    this.setPageBottomPadding();
  },

  onShow() {
    this.setPagePath();
    this.setPageBottomPadding();
  },

  methods: {
    // 设置页面路径
    setPagePath() {
      const app = getApp();
      const pagePathManager = app.globalData.pagePathManager;
      if (pagePathManager) {
        // 获取当前页面路径
        const pages = getCurrentPages();
        if (pages.length > 0) {
          const currentPage = pages[pages.length - 1];
          const route = currentPage.route || currentPage.__route__ || currentPage.path;
          if (route) {
            pagePathManager.setCurrentPath(`/${route}`);
          }
        }
      }
    },

    // 设置页面底部间距
    setPageBottomPadding() {
      const app = getApp();
      const pagePathManager = app.globalData.pagePathManager;
      if (pagePathManager) {
        const style = `padding-bottom: var(--tab-bar-safe-height);`;
        this.setData({ pageBottomStyle: style });
      }
    }
  }
};
